home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_300 / 333_01 / awk1.c < prev    next >
C/C++ Source or Header  |  1989-04-21  |  26KB  |  982 lines

  1.  
  2. /***************************************************************************/
  3. /*                                       */
  4. /*     awk1 -- Expression tree constructors and main program for gawk.       */
  5. /*                                       */
  6. /*         Copyright (C) 1986 Free Software Foundation           */
  7. /*             Written by Paul Rubin, August 1986            */
  8. /*                                       */
  9. /***************************************************************************/
  10. /*                                       */
  11. /* GAWK is distributed in the hope that it will be useful, but WITHOUT ANY */
  12. /* WARRANTY.  No author or distributor accepts responsibility to anyone    */
  13. /* for the consequences of using it or for whether it serves any       */
  14. /* particular purpose or works at all, unless he says so in writing.       */
  15. /* Refer to the GAWK General Public License for full details.           */
  16. /*                                       */
  17. /* Everyone is granted permission to copy, modify and redistribute GAWK,   */
  18. /* but only under the conditions described in the GAWK General Public       */
  19. /* License.  A copy of this license is supposed to have been given to you  */
  20. /* along with GAWK so you can know your rights and responsibilities.  It   */
  21. /* should be in a file named COPYING.  Among other things, the copyright   */
  22. /* notice and this notice must be preserved on all copies.           */
  23. /*                                       */
  24. /* In other words, go ahead and share GAWK, but don't try to stop          */
  25. /* anyone else from sharing it farther.  Help stamp out software hoarding! */
  26. /*                                       */
  27. /***************************************************************************/
  28. /*                                       */
  29. /* Extensive code restructuring and port to MSDOS and MS OS/2 by:       */
  30. /*                                       */
  31. /*                  Bob Withers                   */
  32. /*               649 Meadowbrook St.                   */
  33. /*               Allen, Texas 75002                   */
  34. /*                December 8, 1988                   */
  35. /*                                       */
  36. /* The current state of gAWK (at least this version) is a subset of the    */
  37. /* AWK langauge as released on Unix in 1985 and defined in the book "The   */
  38. /* AWK Programming Langauge" by Aho, Kernighan, and Weinberger (1988).     */
  39. /* Following are language elements which are not supported in this       */
  40. /* version:                                   */
  41. /*                                       */
  42. /* -  Actions                                   */
  43. /*                                       */
  44. /*    o  User defined functions are not supported               */
  45. /*                                       */
  46. /*    o  The "return [expression]" statement is not supported           */
  47. /*                                       */
  48. /*    o  The "delete array[i]" statement is not supported           */
  49. /*     + Support added for "delete" by BW 01/02/89               */
  50. /*                                       */
  51. /* -  Input/Output                               */
  52. /*                                       */
  53. /*    o  The "close(expr)" statement is not supported               */
  54. /*     +  Support for close() added by BW 12/21/88               */
  55. /*        -    close(exp)   ==> close file represented by "exp"       */
  56. /*        -    close()      ==> close all redirected files           */
  57. /*        -    returns 1 for success, 0 for file not found           */
  58. /*                                       */
  59. /*    o  The "system(cmd_line)" statement is not supported           */
  60. /*     +  Support for "system" added by BW 12/6/88               */
  61. /*                                       */
  62. /*    o  Use of pipes is not supported                                     */
  63. /*                                                                         */
  64. /*    o  Output redirection to files is supported for print and printf     */
  65. /*       but there is not support for input redirection via getline        */
  66. /*                                       */
  67. /* -  Built-in Variables                           */
  68. /*                                       */
  69. /*    o  The following built-in variables are not supported:           */
  70. /*                                       */
  71. /*       ARGC      -- Support added by BW 12/26/88           */
  72. /*       ARGV      -- Support added by BW 12/26/88           */
  73. /*       FNR         -- Support added by BW 12/01/88           */
  74. /*       RLENGTH     -- Support added by BW 12/21/88           */
  75. /*       RSTART     -- Support added by BW 12/21/88           */
  76. /*       SUBSEP     -- Support added by BW 12/26/88           */
  77. /*                                       */
  78. /* -  Built-in String Functions                        */
  79. /*                                       */
  80. /*    o  The following built-in string functions are not supported:       */
  81. /*                                       */
  82. /*       gsub(r, s, t) -- Support added by BW 12/22/88           */
  83. /*       match(s, r)     -- Support added by BW 12/21/88           */
  84. /*       sub(r, s, t)  -- Support added by BW 12/22/88           */
  85. /*                                       */
  86. /* -  Built-in Arithmetic Functions                       */
  87. /*                                       */
  88. /*    o  The following built-in arithmetic functions are not supported:    */
  89. /*                                       */
  90. /*       atan2(y, x)     -- Support added by BW 12/03/88           */
  91. /*       cos(x)     -- Support added by BW 12/03/88           */
  92. /*       rand()     -- Support added by BW 12/20/88           */
  93. /*       sin(x)     -- Support added by BW 12/03/88           */
  94. /*       srand(x)     -- Support added by BW 12/20/88           */
  95. /*                                       */
  96. /* -  Expression Operators                           */
  97. /*                                       */
  98. /*    o  The match operator (~) and not match operator (!~) only work       */
  99. /*     on hardcoded regular expressions.  They do not work on regular    */
  100. /*     expressions in a variable.                       */
  101. /*     + Support for matching regular expression stored in a variable    */
  102. /*       added by BW 01/06/88.  The variable is forced to a string and   */
  103. /*       compiled as a regular expression.  If it contains an invalid    */
  104. /*       regular expression execution is terminated with error msg.       */
  105. /*                                       */
  106. /*    o  The exponentiation operator (^) is not supported           */
  107. /*     + Support for ^ added by BW 12/12/88.                   */
  108. /*                                                                         */
  109. /*    o  The conditional expression "exp1 ? exp2 : exp3" is not supported  */
  110. /*     + This has been fixed by BW on 12/20/88               */
  111. /*                                       */
  112. /* -  Misc                                   */
  113. /*                                       */
  114. /*    o  Source lines to be continued MUST be terminated by a backslash.   */
  115. /*     Unix AWK allows lines to be continued at a comma without a       */
  116. /*     backslash, gAWK does not.                       */
  117. /*     + This was fixed by BW 12/13/88                   */
  118. /*                                       */
  119. /*    o  Unix AWK allows a simple print statement to either use parens       */
  120. /*     or not.  gAWK does not allow parens on simple print's.            */
  121. /*     + This was fixed by BW 12/13/88                   */
  122. /*                                       */
  123. /*    o  gAWK only allowed a single level of subscripting on array names.  */
  124. /*     This was changed to support multi-level subscripts in the       */
  125. /*     manner described in "The AWK Programming Language" which converts */
  126. /*     multidimension subscripts to a single subscript separated by       */
  127. /*     the value of special variable SUBSEP.                   */
  128. /*                                       */
  129. /*    o  The %f and %e format specifiers for printf() did not work       */
  130. /*     properly.  This was fixed by BW.                   */
  131. /*                                       */
  132. /*    o  Large number of assumptions that sizeof(int) == sizeof(char *)    */
  133. /*     were corrected by BW.                           */
  134. /*                                       */
  135. /*    o  The split() function did not work properly when multiple field    */
  136. /*     separators appeared between fields.  This was fixed by BW.       */
  137. /*                                       */
  138. /*    o  The FS variable was enhanced to support regular expressions       */
  139. /*     rather than the single character field seperator.  While this       */
  140. /*     is not documented in "The AWK Programming Language" it is       */
  141. /*     implemented in the latest AWK version on UNIX (called NAWK).       */
  142. /*     The default value of FS was changed from " " to "[\t ]+".       */
  143. /*                                       */
  144. /* -  gAWK extensions - BW 12/20/88                       */
  145. /*                                       */
  146. /*    o  upper function added to return the string value of its argument   */
  147. /*     converted to all upper case:                       */
  148. /*                                       */
  149. /*          $1 = upper($1)                       */
  150. /*                                       */
  151. /*    o  lower function added to return the string value of its argument   */
  152. /*     converted to all lower case:                       */
  153. /*                                       */
  154. /*          $1 = lower($1)                       */
  155. /*                                       */
  156. /*    o  reverse function added to return the string value of its       */
  157. /*     argument reversed:                           */
  158. /*                                       */
  159. /*          $1 = reverse($1)                       */
  160. /*                                       */
  161. /***************************************************************************/
  162.  
  163.  
  164. #define DRIVER
  165.  
  166. #include <stdio.h>
  167. #include <stdlib.h>
  168. #include <string.h>
  169. #include <stdarg.h>
  170. #include "awk.h"
  171.  
  172. #define VERSION             "3.00"
  173.  
  174. STATIC char *  NEAR PASCAL  extract_module_name(char *argv0);